<?php
declare (strict_types=1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class Excel extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('excel')
            ->setDescription('the test_excel command');
    }

    protected function execute(Input $input, Output $output)
    {
        $filename = time() . rand(10000, 99999) . '.xlsx';
        $disk_path = root_path() . 'public/downloads/' . $filename;
        $model = new \models\Article();
        $data = \think\facade\Db::name('article')->where([])->order('itemid', 'desc')->page(1, 20)->select()->toArray();
        $model->export($disk_path, $data);
        // 指令输出
        $output->writeln('success');
    }
}
